package com.treasure.mall.biz.entity.order;

import com.treasure.mall.biz.entity.BasePO;
import com.treasure.mall.biz.entity.embeddable.ReceivingInfo;
import com.treasure.mall.biz.entity.user.MerchantPO;
import com.treasure.mall.zbq.common.constant.Constant;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 发货单
 *
 * @author allan
 * @date 2019-10-21
 */
@Entity
@Table(name = "zb_deliver_bill")
@Setter
@Getter
@Cacheable(false)
public class DeliverBillPO extends BasePO {
    @Id
    @Column(name = "id", length = 30)
    private String id;
    @Column(name = "sub_order_id")
    private String subOrderId;
    /**
     * 所属商家
     */
    @ManyToOne
    @JoinColumn(name = "merchant_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private MerchantPO merchantPO;
    @Column(name = "express_no")
    private String expressNo;
    @Column(name = "express_com")
    private String expressCom;
    @Column(name = "express_com_code")
    private String expressComCode;
    private ReceivingInfo receivingInfo;
    @Column(name = "from_role")
    private OrderEnums.DeliverRole from;
    @Column(name = "to_role")
    private OrderEnums.DeliverRole to;
    @Column(name = "deliver_type")
    private OrderEnums.DeliverType deliverType;
    /**
     * 运费
     */
    @Column(name = "freight_amount")
    private BigDecimal freightAmount;
    @Column(name = "remark")
    private String remark;
    /**
     * 是否签收
     */
    @Column(name = "is_received")
    private boolean received;
    /**
     * 最迟收获时间，自动签收
     */
    @Column(name = "last_received_time", columnDefinition = Constant.DATE_COLUMN_DEFINITION)
    private LocalDateTime lastReceivedTime;
    /**
     * 签收时间
     */
    @Column(name = "received_time", columnDefinition = Constant.DATE_COLUMN_DEFINITION)
    private LocalDateTime receivedTime;
    @OneToMany(mappedBy = "deliverBillPO", fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private List<DeliverItemPO> deliverItemPOS;
}
